package com.qf.cardlikeboot.controller;

import com.qf.cardlikeboot.entity.User;
import com.qf.cardlikeboot.request.Request;
import com.qf.cardlikeboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;

    @PostMapping("login")
    public Request<User> login(String username,String password,String code){
        User login = userService.login(username, password);
        if (Objects.nonNull(login)){
            return Request.success(login);
        }else {
            return Request.fail(-1,"用户名或密码错误",null);
        }
    }


    @GetMapping("like")
    public Request<User> like(Integer userId,Integer card,Boolean like){
        User user = userService.likeCard(userId, card, like);
        return Request.success(user);
    }
}
